import yaml
import jinja2
from settings.settings import Route


class ReadYamlRender:

    def __init__(self, yaml_path, content: dict = {}):
        self._yaml_path = yaml_path
        self._content = content

        with open(yaml_path, encoding="utf-8") as w:
            self._string_var = w.read()

    @property
    def render(self):
        response = jinja2.Template(self._string_var).render(self._content)
        results = yaml.safe_load(response)
        return results


if __name__ == '__main__':
    pass
    # 测试下封装是否正确
    # new_data = {"token": "被替换的成功的数据-1"}
    # BASE_DIR = Path(__file__).resolve().parent.parent
    # FILE_PATH = Path.joinpath(BASE_DIR, "bin", "example.yml")
    # print(ReadYamlRender(Route().testcases('getToken.yaml'), new_data).render)
